#ifndef _MYDB_H
#define _MYDB_H

#include <stdlib.h>

#define Key_Mx_Len 65535

struct index_t_ {
	int32_t pageNo;
	u_int16_t key_len;
	u_int32_t dat_len;
	char key[Key_Mx_Len];
	struct index_t_ *next;
};

typedef struct index_t_ Index_t;

struct page_t_ {
	u_int32_t num;
	void *data;
	u_int16_t datalen;
	int using;

	struct page_t_ *next;
};
typedef struct page_t_ Page_t;

extern int mydb_init();
extern int mydb_close();

extern int mydb_save(const char *key, const void *value, u_int32_t len);
extern int mydb_del(const char *key);
extern Index_t* mydb_query(const char *key);
extern int mydb_queryDat(const Index_t *index, void *value);

/***something about index**/

extern Index_t* buildIndex(char *indexfile);
extern int releaseIndex(Index_t *index);

/**
 * 0 no this key
 * >0 use pageNo param
 */
extern int queryIndex(char *key, u_int32_t *pageNo);
extern int newIndex(char *key, u_int32_t pageNo);
extern int removeIndex(char *key);

/***something about store**/
extern u_int32_t saveData(char *data, u_int16_t len);
extern int removeData(u_int32_t pageNo);
extern u_int16_t getData(u_int16_t pageNo, char *data);
#endif // mydb.h
